package com.lovo.invoicing.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lovo.invoicing.bean.BuyInfoBean;
import com.lovo.invoicing.bean.PageBean;
import com.lovo.invoicing.bean.vo.BuyInfoBuyBean;
import com.lovo.invoicing.mapper.BuyInfoMapper;
import com.lovo.invoicing.service.IBuyInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BuyInfoServiceImpl extends ServiceImpl<BuyInfoMapper, BuyInfoBean> implements IBuyInfoService {
    @Autowired
    BuyInfoMapper buyInfoMapper;
    @Override
    public IPage<BuyInfoBean> queryBuyInfoByPage(PageBean<BuyInfoBean> pageBean) {
        QueryWrapper<BuyInfoBean> qw = new QueryWrapper<>();
        if (pageBean.getT().getProviderName()!=null && !"".equals(pageBean.getT().getProviderName())){
            qw.like("provider_name",pageBean.getT().getProviderName());
        }
        if (pageBean.getStartDate()!=null && !"".equals(pageBean.getStartDate())){
            qw.ge("buy_date",pageBean.getStartDate());
        }
        if (pageBean.getEndDate()!=null && !"".equals(pageBean.getEndDate())){
            qw.le("buy_date",pageBean.getEndDate());
        }
        return baseMapper.selectPage(new Page<>(pageBean.getPageNo(), pageBean.getPageSize()),qw);
    }

    @Override
    public List<BuyInfoBuyBean> queryByBuyInfoId(int buyInfoId) {
        return buyInfoMapper.selectByBuyInfoId(buyInfoId);
    }

    @Override
    public int addBuyInfo(BuyInfoBean buyInfoBean) {
        buyInfoMapper.insert(buyInfoBean);
        return buyInfoBean.getBuyinfoId();
    }
}
